define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    $("#c-name").data("params", function (obj) {
        return {custom: {type: $("#c-type").val()}};
    });

    //直冲类型
    var a = $("#flag option:selected").val();
    if (a == 2) {
        $("#zhichongleixing") . show();
        $("#couponprice") . hide();
        $("#brand") . hide();
    } else if (a == 1) {
        $("#couponprice") . show();
        $("#zhichongleixing") . hide();
        $("#brand") . show();
    } else {
        $("#couponprice") . hide();
        $("#zhichongleixing") . hide();
        $("#brand") . hide();
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coupon_code_category/index' + location.search,
                    add_url: 'coupon_code_category/add',
                    edit_url: 'coupon_code_category/edit',
                    del_url: 'coupon_code_category/del',
                    multi_url: 'coupon_code_category/multi',
                    table: 'coupon_code_category',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'stock', title: __('Stock')},
                        {field: 'name', title: __('码库名称'),operate:'LIKE'},
                        {field: 'code_marking', title: __('网络标识或批次号')},
                        {field: 'brand_name', title: __('所属商户')},
                        {field: 'flag.name', title: __('Flag')},
                        {field: 'is_enable', title: __('Is_enable'), formatter: Table.api.formatter.toggle},
                        {field: 'add_time', title: __('Add_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            $("#c-coupon_code").data("params", function (obj) {
                return {custom: {id: $("#c-brand_id").val()}};
            });
            //直冲类型
            $("#flag").change(function () {
                var a = $("#flag option:selected") . val();
                if (a == 2) {
                    $("#zhichongleixing") . show();
                    $("#couponprice") . hide();
                    $("#brand") . hide();
                } else if (a == 1) {
                    $("#couponprice") . show();
                    $("#zhichongleixing") . hide();
                    $("#brand") . show();
                } else {
                    $("#couponprice") . hide();
                    $("#zhichongleixing") . hide();
                    $("#brand") . hide();
                }
            })
            Controller.api.bindevent();
        },
        edit: function () {
            //直冲类型
            $("#flag").change(function () {
                var a = $("#flag option:selected") . val();
                if (a == 2) {
                    $("#zhichongleixing") . show();
                    $("#couponprice") . hide();
                    $("#brand") . hide();
                } else if (a == 1) {
                    $("#couponprice") . show();
                    $("#zhichongleixing") . hide();
                    $("#brand") . show();
                } else {
                    $("#couponprice") . hide();
                    $("#zhichongleixing") . hide();
                    $("#brand") . hide();
                }
            })

            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;

});